import {
    createStore
} from "redux"

function fn(state = {carList: []}, action) {
    switch (action.type) {
        case "jia":
            let s1 = JSON.parse(JSON.stringify(state))

            let index = s1.carList.findIndex(v => v.id == action.obj.id);

            if (index == -1) {
                action.obj.num = 1;
                s1.carList.push(action.obj)
            } else {
                s1.carList[index].num += 1
            }

            state = s1;
            return state;
        default:
            return state;
    }
}



const store = createStore(fn);
export default store;